package com.cauli.file.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cauli.model.entity.BaseEntity;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qiwenshare.ufop.operation.upload.domain.UploadFileResult;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author Cauli
 * @date 2023-03-18 12:00
 * @description
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("file")
@ApiModel(value = "File", description = "文件")
public class FileEntity extends BaseEntity {
    /**
     * 文件信息
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @TableId("file_id")
    private Long fileId;

    /**
     * 文件大小
     */
    @TableField("file_size")
    private Long fileSize;

    /**
     * 文件状态(0-失效，1-生效)
     */
    @TableField("file_status")
    private Integer fileStatus;

    /**
     * 文件url
     */
    @TableField("file_url")
    private String fileUrl;

    /**
     * md5唯一标识
     */
    @TableField("identifier")
    private String identifier;

    /**
     * 存储类型
     */
    @TableField("storage_type")
    private Integer storageType;

    public FileEntity(){

    }

    public FileEntity(UploadFileResult uploadFileResult) {
        this.fileUrl = uploadFileResult.getFileUrl();
        this.fileSize = uploadFileResult.getFileSize();
        this.fileStatus = 1;
        this.storageType = uploadFileResult.getStorageType().getCode();
        this.identifier = uploadFileResult.getIdentifier();
    }

    public FileEntity(String fileUrl, Long fileSize, Integer storageType, String identifier, Long userId) {
        this.fileUrl = fileUrl;
        this.fileSize = fileSize;
        this.fileStatus = 1;
        this.storageType = storageType;
        this.identifier = identifier;
    }
}
